package m.jclecai.com.view.jsks;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

/**
 * Created by andy on 2017/6/19.
 */

public class MyFrameLayout extends FrameLayout {
    private View mView;

    public MyFrameLayout(Context context) {
        super(context);
    }

    public MyFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        getChildCount();
        int width=0;
        //让高度始终包裹内容；
        int height = MeasureSpec.getSize(heightMeasureSpec);

        for (int i=0;i<getChildCount();i++){
            View childAt = getChildAt(i);
            measureChildWithMargins(childAt,widthMeasureSpec,0,heightMeasureSpec,0);
            int measuredHeight = childAt.getMeasuredHeight();
            int measuredWidth = childAt.getMeasuredWidth();
            width= width>measuredWidth?width:measuredHeight;
            height=height>measuredHeight?height:measuredHeight;
        }
        setMeasuredDimension(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
    }


}
